package org.spring.boot.jdbctemplate.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

/**
 * @author: eastcom
 * @desc:
 **/
@Repository
public class GenerationDaoImpl implements  GenerationDao {

	final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private JdbcTemplate jdbcTemplate;

	@Override
	public int[][] saveArrestpiont(List<String[]> list) {
		StringBuilder builder = new StringBuilder("INSERT INTO PM.PM_WY_EUTRANCELL_15MIN ");
		builder.append(" (time_stamp, city, ci, vo_traffic, vi_traffic , vo_conn_rate, vo_net_conn_rate, vi_conn_rate, vi_net_conn_rate, vi_drop_rate , vo_drop_rate, vv_start_call_duration, va_start_call_duration, srvcc_cut_rate, srvcc_cut_times , mos_value, up_mos_value, down_mos_value, rtp_up_drop_rate,volte_active_user)");
		builder.append(" VALUES (TO_DATE(?,'yyyy-MM-dd HH24:Mi:ss') ,?, ?, ?, ? , ?, ?, ?, ?, ? , ?, ?, ?, ?, ? , ?, ?, ?, ?, ?)");
		return this.jdbcTemplate.batchUpdate(builder.toString(), list, 1000, new ParameterizedPreparedStatementSetter<String[]>() {
			@Override
			public void setValues(PreparedStatement ps, String[] array) throws SQLException {
				for (int i = 0; i < array.length; i++) {
					ps.setString(i + 1, array[i]);
				}
			}
		});
	}
}
